package net.jltec.view.adapter;

import java.util.List;

import net.jltec.view.R;
import net.jltec.view.bean.Model;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ModelListAdapter extends BaseAdapter {
	
	private List<Model> models;
	private Context context;
	private LayoutInflater mInflater;
	
	
	public ModelListAdapter(Context ctx, List<Model> models) {
		this.context = ctx;
		this.models=models;
		mInflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		

	}

	@Override
	public int getCount() {
		return models.size();
	}

	@Override
	public Model getItem(int position) {
		return models.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder = null;

		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.main_model_item, null);
			holder = new Holder();

			TextView modelNameText = (TextView) convertView.findViewById(R.id.model_name_text);
			holder.modelNameText = modelNameText;

			ImageView modelImage = (ImageView) convertView.findViewById(R.id.model_image);
			holder.modelImage = modelImage;

			ImageView mdoelRightJT = (ImageView) convertView.findViewById(R.id.model_right_jt);
			holder.mdoelRightJT = mdoelRightJT;

			convertView.setTag(holder);

		} else {
			holder = (Holder) convertView.getTag();
		}

		 
		holder.modelNameText.setText(getItem(position).name);
		holder.mdoelRightJT.setImageResource(R.drawable.right_jt);
		holder.modelImage.setImageResource(getItem(position).resId);
		return convertView;
	}

	
	static class Holder {
		TextView modelNameText;
		ImageView modelImage;
		ImageView mdoelRightJT;
	}
}
